package array;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Array {
    public static void main(String[] args) {
        String pgpsFilePath = "D:\\test\\Hilbert_spatial_keyword_query\\set\\ds1\\PGPS.txt";
        String retailFilePath = "D:\\test\\Hilbert_spatial_keyword_query\\set\\ds1\\retail.dat";
        String mergedFilePath = "D:\\test\\Hilbert_spatial_keyword_query\\set\\ds1\\retail11.txt";

        try (
                BufferedReader pgpsReader = new BufferedReader(new FileReader(pgpsFilePath));
                BufferedReader retailReader = new BufferedReader(new FileReader(retailFilePath));
                BufferedWriter writer = new BufferedWriter(new FileWriter(mergedFilePath))
        ) {
            String pgpsLine, retailLine;

            while ((pgpsLine = pgpsReader.readLine()) != null && (retailLine = retailReader.readLine()) != null) {
                // Remove the first element and commas from the PGPS line
                String pgpsProcessed = pgpsLine.substring(pgpsLine.indexOf(",") + 1).replace(",", " ");

                // Remove the first element and commas from the retail line
                String retailProcessed = retailLine.substring(retailLine.indexOf(",") + 1).replace(",", " ");

                // Merge the processed lines and write to the new file
                writer.write(pgpsProcessed + " " + retailProcessed);
                writer.newLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
